package com.zrkj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zrkj.entity.Algorithm;
import com.zrkj.entity.vo.Result;
import com.zrkj.service.IAlgorithmService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
/**
 * @author : 司总
 * @className : AlgorithmController
 * @package: com.zrkj.controller
 * @description : 算法表 前端控制器
 * @date :  2023-11-23
 */
@RestController
@RequestMapping(value = "/algorithm")
@Api(tags = "算法表")
public class AlgorithmController {
private final IAlgorithmService ialgorithmService;

public AlgorithmController(IAlgorithmService ialgorithmService){
        this.ialgorithmService=ialgorithmService;
        }

/**
 * 添加
 *
 * @param algorithm
 * @return
 */
@PostMapping("/add")
public Result<String> add(@RequestBody Algorithm algorithm){
        return ialgorithmService.add(algorithm);
        }

/**
 * 更新
 *
 * @param algorithm
 * @return
 */
@PutMapping(value = "/update")
public Result<Boolean> update(@RequestBody Algorithm algorithm){
        return ialgorithmService.update(algorithm);
        }

/**
 * 删除
 *
 * @param ids
 * @return
 */
@DeleteMapping(value = "/delete")
public Result<Boolean> delete(@RequestParam(value = "ids") String ids){
        String[]idsArray=ids.split(",");
        List<String> idList=new ArrayList<>();
        for(String id:idsArray){
        idList.add(id);
        }
        return ialgorithmService.delete(idList);
        }

/**
 * 查询详情
 *
 * @param id
 * @return
 */
@GetMapping(value = "/getById/{id}")
public Result<Algorithm> getById(@PathVariable(value = "id") String id){
        return ialgorithmService.getById(id);
        }

/**
 * 查询列表
 *
 * @param algorithm
 * @return
 */
@PostMapping(value = "/queryList")
public Result<List<Algorithm>>queryList(@RequestBody Algorithm algorithm){
        return ialgorithmService.queryList(algorithm);
        }

/**
 * 查询分页列表
 *
 * @param algorithm
 * @return
 */
@PostMapping(value = "/queryPageList")
public Result<IPage<Algorithm>>queryPageList(@RequestBody Algorithm algorithm){
        return ialgorithmService.queryPageList(algorithm.getPage(), algorithm);
        }
        }
